package com.woniu.account.controller;


import cn.hutool.json.JSONUtil;
import com.woniu.account.dto.venueAdmin.VenueAdminDto;
import com.woniu.account.dto.venuePermission.VenuePermissionDto;
import com.woniu.account.service.VenuePermissionService;
import com.woniu.model.Result;
import com.woniu.util.JwtUtil;
import com.woniu.util.RedisUtil;
import com.woniu.util.WebUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年07月11日
 */
@RestController
@RequestMapping("/venuePermission")
@Api(tags = "场馆管理员权限")
public class VenuePermissionController {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private VenuePermissionService venuePermissionService;

    @ApiOperation("加载场馆管理员的权限资源")
    @GetMapping("/load")
    public Result load() throws Exception {
        String token = WebUtil.getToken();
        String s = redisUtil.get(token);
        VenueAdminDto venueAdminDto = JSONUtil.toBean(JSONUtil.toJsonStr(JwtUtil.getVenueAdmin(s)),VenueAdminDto.class);
        ArrayList<VenuePermissionDto> permissionDtos= venuePermissionService.load(venueAdminDto.getVenueAdminId());
        return Result.getResult().setData(permissionDtos).setMsg("成功");
    }
}

